package com.yiwenup.struct._01_linear.queue;

import com.yiwenup.struct._01_linear.base.List;
import com.yiwenup.struct._01_linear.list.DoublyLinkedList;

/**
 * 双端队列（Double Ended Queue）
 **/
public class Deque<E> {

    private List<E> list = new DoublyLinkedList<>();

    public int size() {
        return list.size();
    }

    public boolean isEmpty() {
        return list.isEmpty();
    }

    public void enQueueHead(E ele) {
        list.insert(0, ele);
    }

    public void enQueueTail(E ele) {
        list.add(ele);
    }

    public E deQueueHead() {
        return list.remove(0);
    }

    public E deQueueTail() {
        return list.remove(list.size() - 1);
    }

    public E head() {
        return list.get(0);
    }

    public E tail() {
        return list.get(list.size() - 1);
    }

    public void clear() {
        list.clear();
    }
}
